/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package replica.transaction;

import generalResourceLalla.Task;
import generalResourceLalla.TaskList;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

/**
 *
 * @author andrea
 */
@XmlType(name = "", propOrder = {
    "serialNumber",
    "operationType",
    "task"
})
public class Operation implements Serializable
{
    private Long serialNumber;
    private OperationType operationType;
    private Task task;
    private TaskList tasklist;
    private long nodeId;
    
    
    public static enum OperationType{ENQUEUE,DEQUEUE,GETLIST,ALIGNMENT};
    
    
    public Operation(){}
    
    public Operation(Long serialNumber,OperationType operationType,Task task,TaskList tasklist, long nodeId)
    {
        this.serialNumber=serialNumber;
        this.operationType=operationType;
        this.task=task;
        this.tasklist=tasklist;
        this.nodeId=nodeId;
        
        //PER DEBUG 
        if(this.operationType==OperationType.ALIGNMENT && this.serialNumber==0)
            throw new UnsupportedOperationException("ERRRRRORE!!!");
        //FINE PER DEBUG
        
    }
    public Operation(Long serialNumber,OperationType operationType,Task task, long nodeId)
    {
        this(serialNumber, operationType, task, null,nodeId);
    }

    public Long getSerialNumber() {
        return serialNumber;
    }

    public void setSerialNumber(Long serialNumber) {
        this.serialNumber = serialNumber;
    }

    public Task getTask() {
        return task;
    }

    public void setTask(Task task) {
        this.task = task;
    }

    public OperationType getOperationType() {
        return operationType;
    }

    public void setOperationType(OperationType operationType) {
        this.operationType = operationType;
    }

    public long getNodeId() {
        return nodeId;
    }

    public TaskList getTasklist() {
        return tasklist;
    }

    
    
    
    
    public String toString()
    {
        return "{serialNum="+serialNumber+", type="+operationType+"}";
    }
    
    public String toStringVerbose()
    {
        return "{serialNum="+serialNumber+", type="+operationType+"task="+task+"}";
    }
    
    public static Operation buildGetListOperation(long nodeId)
    {
        return new Operation(null,OperationType.GETLIST,null,nodeId);
    }
 
    public static Operation buildAlignmentOperation(TaskList list, long nodeId)
    {
        Operation returnValue=new Operation(list.getSerial(),OperationType.ALIGNMENT,null,list,nodeId );
        return returnValue;
    }
    
    
}
